package com.api.shopapi.config;


import com.alipay.api.internal.util.file.IOUtils;
import com.api.shopapi.util.wxutil.IWXPayDomain;
import com.api.shopapi.util.wxutil.WXPayConfig;
import com.api.shopapi.util.wxutil.WXPayConstants;

import java.io.*;

public class WxConfig extends WXPayConfig {

    private byte[] certData;

    private String app_id="wx0b163313f7db95aa";

    private String wx_pay_key="03123632860zhang03123632860zhang";

    private String wx_pay_mch_id="1550031831";

    private String certPath="templates/apiclient_cert.p12";

    public static String notify_url = "http://shopapi.ltylao.com:9987/PayNotify/WxPayNotify";


    public WxConfig() throws Exception { // 构造方法读取证书, 通过getCertStream 可以使sdk获取到证书
        InputStream certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(certPath);
        this.certData = IOUtils.toByteArray(certStream);
        certStream.close();
    }


    @Override
    public String getAppID() {
        return app_id;
    }

    @Override
    public String getMchID() {
        return wx_pay_mch_id;
    }

    @Override
    public String getKey() {
        return wx_pay_key;
    }

    @Override
    public InputStream getCertStream() {
        return new ByteArrayInputStream(this.certData);
    }

    @Override
    public IWXPayDomain getWXPayDomain() { // 这个方法需要这样实现, 否则无法正常初始化WXPay
        IWXPayDomain iwxPayDomain = new IWXPayDomain() {
            @Override
            public void report(String domain, long elapsedTimeMillis, Exception ex) {

            }

            @Override
            public DomainInfo getDomain(WXPayConfig config) {
                return new IWXPayDomain.DomainInfo(WXPayConstants.DOMAIN_API, true);
            }
        };
        return iwxPayDomain;
    }


//   public static String appId="wx0b163313f7db95aa";
//
//    public static String appSecret="0295686ed2711f0989665b0f837193be";
//
//    public static String mchId="1550031831";
//
//    public static String mchKey="03123632860zhang03123632860zhang";
//
//    public static String notifyUrl="http://shopdebugapi.ltylao.com:6019/PayNotify/WxPayNotify";
//
//    //微信支付证书地址
//    @Value("${wx.certificate}")
//    public static String certificate;
//
//
//    //微信统一下单的url
//    public static String unifiedorder_url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
//
//    //微信查询订单的url
//    public static String orderquery_url = "https://api.mch.weixin.qq.com/pay/orderquery";

}
